AVR_TOOLCHAIN = /home/manik/tools/avr/avr8-gnu-toolchain-linux_x86/bin

#Get rid of compiler warning, define F_CPU as 1mhz for atmega16a
F_CPU = 1000000
MCU = atmega16a


PROGRAM = led-blink
CC = $(AVR_TOOLCHAIN)/avr-gcc
OBJCOPY = $(AVR_TOOLCHAIN)/avr-objcopy
CFLAGS += -Wall -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU)
LDFLAGS +=
OBJS = led-blink.o 

 
# Be silent per default, but 'make V=1' will show all compiler calls.
ifeq ($(V),0)
Q := @
endif
 
all: $(PROGRAM).hex
 
$(PROGRAM).elf: $(OBJS)
	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
 
$(PROGRAM).hex: $(PROGRAM).elf
	$(Q)$(OBJCOPY) -O ihex $< $@
 
%.o: %.c
	$(Q)$(CC) $(CFLAGS) -o $@ -c $<
 
flash: $(PROGRAM).hex
	$(Q)sudo avrdude -p atmega16 -P usb -c avrisp2 -U flash:w:$(PROGRAM).hex -v
	#$(Q)sudo avrdude -c avrispv2 -P usb -p t13 -U flash:w:$(PROGRAM).hex
 
clean:
	$(Q)rm -f $(OBJS)
	$(Q)rm -f *.elf
	$(Q)rm -f *.hex
